package list;

import java.io.*;

public class Main {
	static class Node {
		int val;
		Node next;

		public Node(int val) {
			this.val = val;
		}
	}

	public static Node createList(int n) {
		if (n < 1) {
			return null;
		}
		// 构建[1...n]的序列
		Node head = new Node(1);
		Node tail = head;
		for (int i = 2; i <= n; i++) {
			tail.next = new Node(i);
			tail = tail.next;
		}
		tail.next = head;// 成环。
		return head;
	}

	public static Node josephusKilll(Node head, int k) {
		// 链表为空，单节点的循环链表，输入k不合理的逻辑。
		if (head == null || head.next == head || k < 1) {
			return head;
		}
		Node cur = head.next;
		int n = 1;
		while(cur != head) {
			n++;
			cur = cur.next;
		}
		n = compute(n,k);
		while(--n != 0) {
			head = head.next;
		}
		head.next = head;
		return head;
	}

	public static Node josephusKilll(Node head, int k) {
		// 链表为空，单节点的循环链表，输入k不合理的逻辑。
		if (head == null || head.next == head || k < 1) {
			return head;
		}
		Node last = head;// last是head的前驱节点
		while (last.next != head) {
			last = last.next;
		}
		int count = 0;// 计数变量
		while (head != last) {
			if (++count == k) {
				last.next = head.next;// 删除head引用节点
				count = 0;// 重新计数
			} else {
				last = last.next;
			}
			head = last.next;
		}
		return head;
	}

	public static int compute(int n, int k) {
		Node head = createList(n);// 创建单向循环链表
		head = josephusKilll(head, k);// 返回约瑟夫环最后的节点。
		return head == null ? -1 : head.val;
	}

//	public static int compute(int n, int k){
//		int ans = 1;//初始编号为1
//		for(int i=2;i<=n;i++) {
//			ans = (ans + k-1)%i + 1;
//		}
//		return ans;
//	}
	public static int compute(int n, int k) {
		if (n == 1) {
			return 1;// 编号从1开始
		} else {
			return (compute(n - 1, k) + k - 1) % n + 1;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StreamTokenizer in = new StreamTokenizer(br);
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		in.nextToken();
		int n = (int) in.nval;
		in.nextToken();
		int k = (int) in.nval;
		out.println(compute(n, k));
		out.close();
		br.close();
	}
}

//import java.io.*;

//public class Main{
//  public static int compute(int n, int k){
//      int ans = 1;
//      for(int c = 2;c <= n; c++){
//          ans = (ans + k - 1)%c + 1;
//      }
//      return ans;
//  }
//  public static void main(String[] args) throws IOException{
//      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//      StreamTokenizer in = new StreamTokenizer(br);
//      PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
//      in.nextToken();
//      int n = (int)in.nval;
//      in.nextToken();
//      int k = (int)in.nval;
//      out.println(compute(n, k));
//      out.close();
//      br.close();
//  }
//}